package com.xidian.zhiancloud.service.luling;

import com.xidian.zhiancloud.dao.RiskLedgerStatusMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.RiskLedgerStatus;
import com.xidian.zhiancloud.model.RiskLedgerStatusExample;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 风险台账
 */
@Service
public class RiskLedgerStatusService {

    @Autowired
    private RiskLedgerStatusMapper riskLedgerStatusMapper;
    private Date time;
    private String riskColor;

    //批量修改
    public void updateByIds(List<RiskLedgerStatus> riskLedgerStatusList) {
        for (RiskLedgerStatus riskLedgerStatus : riskLedgerStatusList) {
            RiskLedgerStatus riskLedgerStatus1 = new RiskLedgerStatus();
            BeanUtils.copyProperties(riskLedgerStatus, riskLedgerStatus1);
            riskLedgerStatus1.setDelStatus(Boolean.valueOf("1"));
            int result = riskLedgerStatusMapper.updateByPrimaryKey(riskLedgerStatus1);
            if (result == 0) {
                throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
            }
        }
    }

    //查询
    public Object getList(String riskType, String companyId, String controlLevel, String riskName, String itemName,
                          String itemStandard, String itemSituation, String itemCons, String levelEval, String levelRisk,
                          String levelProp, String controlTech, String controlStep, String controlEdu,
                          String controlProtec, String controlEmerg, String locale, String eval,
                          String unit, String personLiable, String riskValue,
                          int current, int size) {
//        RiskLedgerStatusExample riskLedgerStatusExample = new RiskLedgerStatusExample();
//        riskLedgerStatusExample.createCriteria().andCompanyIdEqualTo(Long.valueOf(companyId));
//        if (controlLevel != null) {
//            riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(controlLevel);
//        }
//        if (riskType != null) {
//            riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(riskType);
//        }
//        if (riskName != null) {
//            riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(riskName);
//        }
//        if (itemName != null) {
//            riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(itemName);
//        }
//        if (itemStandard != null) {
//            riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(itemStandard);
//        }
//        if (itemSituation != null) {
//            riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(itemSituation);
//        }
//        if (levelEval != null) {
//            riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(levelEval);
//        }
//        if (levelRisk != null) {
//            riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(levelRisk);
//        }
//        if (levelProp != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(levelProp);
//            }
//        if (controlTech != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(controlTech);
//            }
//        if (controlStep != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(controlStep);
//            }
//        if (controlEdu != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(controlEdu);
//            }
//        if (controlProtec != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(controlProtec);
//            }
//        if (riskValue != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(riskValue);
//            }
//        if (riskColor != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(riskColor);
//            }
//        if (locale != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(locale);
//            }
//        if (controlEmerg != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(controlEmerg);
//            }
//        if (eval != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(eval);
//            }
//        if (personLiable != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(personLiable);
//            }
//        if (itemCons != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(itemCons);
//            }
//        if (unit != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andAssessedDepartmentIdEqualTo(unit);
//            }
//        if (time != null) {
//                riskLedgerStatusExample.getOredCriteria().get(0).andCreateTimeBetween(time);
//            }
//        RowBounds rowBounds = new RowBounds(current, size);
//            return riskLedgerStatusExample.selectByExampleWithRowbounds(riskLedgerStatusExample, rowBounds);
        return null;
    }
    //单个修改
        public void singleupdate (RiskLedgerStatus riskLedgerStatus){
            RiskLedgerStatusExample example = new RiskLedgerStatusExample();
            RiskLedgerStatusExample.Criteria criteria = example.createCriteria();
            criteria.andIdEqualTo(riskLedgerStatus.getId());
            RiskLedgerStatus riskLedgerStatus1 = new RiskLedgerStatus();
            riskLedgerStatus1.setCompanyId(riskLedgerStatus.getCompanyId());
            riskLedgerStatus1.setControlLevel(riskLedgerStatus.getControlLevel());
            riskLedgerStatus1.setRiskType(riskLedgerStatus.getRiskType());
            riskLedgerStatus1.setRiskName(riskLedgerStatus.getRiskName());
            riskLedgerStatus1.setItemName(riskLedgerStatus.getItemName());
            riskLedgerStatus1.setItemStandard(riskLedgerStatus.getItemStandard());
            riskLedgerStatus1.setItemSituation(riskLedgerStatus.getItemSituation());
            riskLedgerStatus1.setLevelEval(riskLedgerStatus.getLevelEval());
            riskLedgerStatus1.setLevelRisk(riskLedgerStatus.getLevelRisk());
            riskLedgerStatus1.setLevelProp(riskLedgerStatus.getLevelProp());
            riskLedgerStatus1.setControlTech(riskLedgerStatus.getControlTech());
            riskLedgerStatus1.setControlStep(riskLedgerStatus.getControlStep());
            riskLedgerStatus1.setControlEdu(riskLedgerStatus.getControlEdu());
            riskLedgerStatus1.setControlProtec(riskLedgerStatus.getControlProtec());
            riskLedgerStatus1.setControlEmerg(riskLedgerStatus.getControlEmerg());
            riskLedgerStatus1.setLocale(riskLedgerStatus.getLocale());
            riskLedgerStatus1.setEval(riskLedgerStatus.getEval());
            riskLedgerStatus1.setRiskValue(riskLedgerStatus.getRiskValue());
            riskLedgerStatus1.setRiskColor(riskLedgerStatus.getRiskColor());
            riskLedgerStatus1.setUnit(riskLedgerStatus.getUnit());
            riskLedgerStatus1.setPersonLiable(riskLedgerStatus.getPersonLiable());
            riskLedgerStatus1.setTime(riskLedgerStatus.getTime());
            int count = riskLedgerStatusMapper.updateByExampleSelective(riskLedgerStatus1, example);
            if (count == 0) {
                throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
            }
        }



}
